home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / edit / TSMrph23s.lha / TSM23s.lha / loadilbm.c < prev    next >
C/C++ Source or Header  |  1993-09-11  |  5KB  |  218 lines

  1. //    $Author: M_J_Paddock $
  2. //    $Date: 1993/06/27 19:56:57 $
  3. //    $Revision: 1.3 $
  4.  
  5. /* loadilbm.c - C. Scheppner CBM
  6.  *
  7.  * High-level ILBM load routines
  8.  *
  9.  * 37.9  04/92 - use vp->ColorMap.Count instead of MAXAMCOLORREG
  10.  */
  11. // Minor edits for error handling MJP
  12.  
  13. #define INTUI_V36_NAMES_ONLY
  14.  
  15. #include "iffp/ilbm.h"
  16. #include "iffp/ilbmapp.h"
  17.  
  18. extern struct Library *GfxBase;
  19.  
  20. /* loadbrush
  21.  *
  22.  * Passed an initialized ILBMInfo with a not-in-use ParseInfo.iff
  23.  *   IFFHandle and desired propchks, collectchks, and stopchks, and filename,
  24.  *   will load an ILBM as a brush, setting up ilbm->Bmhd, ilbm->camg,
  25.  *   ilbm->brbitmap, ilbm->colortable, and ilbm->ncolors
  26.  *
  27.  *   Note that ncolors may be more colors than you can LoadRGB4.
  28.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  29.  *   you change the colors yourself using 1.3/2.0 functions.
  30.  *
  31.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  32.  */
  33.  
  34. LONG loadbrush(struct ILBMInfo *ilbm, UBYTE *filename)
  35. {
  36. LONG error = 0L;
  37.  
  38.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  39.  
  40.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  41.     {
  42.     error = parseifile((struct ParseInfo *)ilbm,
  43.                 ID_FORM, ID_ILBM,
  44.                 ilbm->ParseInfo.propchks,
  45.                 ilbm->ParseInfo.collectchks,
  46.                 ilbm->ParseInfo.stopchks);
  47.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  48.         {
  49.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  50.         {
  51.             if(error = createbrush(ilbm))   deletebrush(ilbm);
  52.         }
  53.         else
  54.         {
  55.         message(SI(MSG_IFFP_NOILBM),NULL,6);        // MJP 6 = IFFILBM
  56.         error = NOFILE;
  57.         }
  58.         }
  59.     if(error)    closeifile((struct ParseInfo *)ilbm);
  60.     }
  61.     return(error);
  62. }
  63.  
  64.  
  65. /* unloadbrush
  66.  *
  67.  * frees and close everything alloc'd/opened by loadbrush
  68.  */
  69. void unloadbrush(struct ILBMInfo *ilbm)
  70. {
  71.     deletebrush(ilbm);
  72.     closeifile((struct ParseInfo *)ilbm);
  73. }
  74.  
  75.  
  76. /* queryilbm
  77.  *
  78.  * Passed an initilized ILBMInfo with a not-in-use IFFHandle,
  79.  *   and a filename,
  80.  *   will open an ILBM, fill in ilbm->camg and ilbm->bmhd,
  81.  *   and close the ILBM.
  82.  *
  83.  * This allows you to determine if the ILBM is a size and
  84.  *   type you want to deal with.
  85.  *
  86.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  87.  */
  88.  
  89. /* query just wants these chunks */
  90. LONG queryprops[] = { ID_ILBM, ID_BMHD,
  91. //              ID_ILBM, ID_CAMG,
  92.                       TAG_DONE };
  93.  
  94. /* scan can stop when a CMAP or BODY is reached */
  95. LONG querystops[] = { ID_ILBM, ID_CMAP,
  96.               ID_ILBM, ID_BODY,
  97.               TAG_DONE };
  98.  
  99. LONG queryilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  100. {
  101. LONG error = 0L;
  102. BitMapHeader *bmhd;
  103.  
  104.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  105.  
  106.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  107.     {
  108.     D(bug("queryilbm: openifile successful\n"));
  109.  
  110.     error = parseifile((struct ParseInfo *)ilbm,
  111.             ID_FORM, ID_ILBM,
  112.             queryprops, NULL, querystops);
  113.  
  114.     D(bug("queryilbm: after parseifile, error = %ld\n",error));
  115.  
  116.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  117.         {
  118.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  119.         {
  120.         if(bmhd = (BitMapHeader*)
  121.             findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD))
  122.             {
  123.             *(&ilbm->Bmhd) = *bmhd;
  124. //            ilbm->camg = getcamg(ilbm);    MJP
  125.             }
  126.         else error = NOFILE;
  127.         }
  128.         else
  129.         {
  130. //        message(SI(MSG_IFFP_NOILBM),NULL,6);        // MJP
  131.         error = NOFILE;
  132.         }
  133.         }
  134.     closeifile(ilbm);
  135.     }
  136.     return(error);
  137. }
  138.  
  139. /* loadilbm
  140.  *
  141.  * Passed a not-in-use IFFHandle, an initialized ILBMInfo, and filename,
  142.  *   will load an ILBM into your already opened ilbm->scr, setting up
  143.  *   ilbm->Bmhd, ilbm->camg, ilbm->colortable, and ilbm->ncolors
  144.  *   and loading the colors into the screen's viewport
  145.  *
  146.  *   Note that ncolors may be more colors than you can LoadRGB4.
  147.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  148.  *   you change the colors yourself using 1.3/2.0 functions.
  149.  *
  150.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  151.  *
  152.  * NOTE - loadilbm() keeps the IFFHandle open so you can copy
  153.  *   or examine other chunks.  You must call closeifile(iff,ilbm)
  154.  *   to close the file and deallocate the parsed context
  155.  *
  156.  */
  157. /*    MJP
  158. LONG loadilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  159. {
  160. LONG error = 0L;
  161.  
  162.  
  163.     D(bug("loadilbm:\n"));
  164.  
  165.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  166.     if(!ilbm->scr)        return(CLIENT_ERROR);
  167.  
  168.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  169.     {
  170.     D(bug("loadilbm: openifile successful\n"));
  171.  
  172.     error = parseifile((struct ParseInfo *)ilbm,
  173.             ID_FORM, ID_ILBM,
  174.             ilbm->ParseInfo.propchks,
  175.             ilbm->ParseInfo.collectchks,
  176.             ilbm->ParseInfo.stopchks);
  177.  
  178.     D(bug("loadilbm: after parseifile, error = %ld\n",error));
  179.  
  180.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  181.         {
  182.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  183.         {
  184.             error = loadbody(ilbm->ParseInfo.iff,
  185.                     &ilbm->scr->BitMap, &ilbm->Bmhd);
  186.  
  187.         D(bug("loadilbm: after loadbody, error = %ld\n",error));
  188.  
  189.         if(!error)
  190.             {
  191.             if(!(getcolors(ilbm)))
  192.                 LoadRGB4(&ilbm->scr->ViewPort,ilbm->colortable,
  193.             MIN(ilbm->ncolors,ilbm->scr->ViewPort.ColorMap->Count));
  194.             } 
  195.         }
  196.         else
  197.         {
  198.         message(SI(MSG_IFFP_NOILBM),NULL,6);        // MJP
  199.         error = NOFILE;
  200.         }
  201.         }
  202.     if(error)    closeifile((struct ParseInfo *)ilbm);
  203.     }
  204.     return(error);
  205. }
  206. */
  207.  
  208. /* unloadilbm
  209.  *
  210.  * frees and closes everything allocated by loadilbm
  211.  */
  212. /* MJP
  213. void unloadilbm(struct ILBMInfo *ilbm)
  214. {
  215.     closeifile((struct ParseInfo *)ilbm);
  216.     freecolors(ilbm);
  217. }
  218. */